package com.tianji.aigc.controller;

import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 向量化数据处理
 *
 * @Author mr.wu
 * @Date 2025-9-3 11:58
 */
@RestController
@RequestMapping("/embedding")
public class EmbeddingController {

    @Autowired
    private VectorStore vectorStore;

    /**
     * 添加文档到ES向量索引库
     * @param messageList
     */
    @PostMapping
    public void addDocumentToVectstore(@RequestParam("messages")List<String> messageList){
        //1.数据类型转换，字符串->Document
        List<Document> documentList = messageList.stream()
                .map(x -> Document.builder().text(x).build())
                .toList();

        //2.将文档导入到ES向量数据库
        vectorStore.add(documentList);
    }
}
